/* 
 Project     : 48c6c450f1a4a0cc53d9585dc0fee742
 Created on  : Mar 16, 2013, 11:29:15 PM
 Author      : Truong Khuong - khuongxuantruong@gmail.com
 Description :
 Purpose of the stylesheet follows.
 */
var _CONFIG = {
    JQXGRID_ELEMENT: '#jqxGrid_Backend_Categories',
    _TYPE: 'kitchen',
    BINDING_URI: base_url + 'backend/system/binding/',
    EDIT_PANEL_URI: base_url + "backend/system/editpanel",
    COMMIT_URI: base_url + "backend/excution/commit/config/config/conf",
    DELETE_URI: base_url + "backend/excution/delete/config/config/conf",
    PENDING: false,
    PAGE: 0,
    PAGESIZE: 20
};
var _SOPLUGIN = (function() {
    var init = false;
    return {
        LoadData: function(_page) {
            _CONFIG.PAGE = _page;
            $('#requestDataList').load(_CONFIG.BINDING_URI, {
                pagenum: _CONFIG.PAGE,
                pagesize: _CONFIG.PAGESIZE
            },function(){
               $.jGrowl('Load data success !'); 
            });
        },
        OnInit: function() {
            try {
                if (init)
                    return;
                init = true;
                //grid_element=$('#jqxGrid_Backend_Categories');
                this.LoadData(_CONFIG.PAGE);

            } catch (e) {
                bootbox.alert(e.message);
            }
        },
        AddItem: function() {
            this.EditItem(0);
        },
        AddItemIn: function() {
            this.EditItemIn(0);
        },
        EditItem: function(Id) {
            if (PENDING)
                return false;
            bckdialog({
                title:'Setting',
                message:$('#dialog-notications'),
                buttons: [
                    {
                        text    :'Done',
                        class   :'base_button base_green',
                        click   : function() {
                            _SOPLUGIN.Save();
                        }
                    },{
                        text    :'Cancel',
                        class   :'base_button base_red',
                        click   : function() {
                            $(this).dialog("close");
                        }
                    }
                ]
            }).open();
            new backend({
                url: _CONFIG.EDIT_PANEL_URI,
                data: {
                    Id: Id,
                    Type:_CONFIG._TYPE
                },
                callback: function(rsdata) {
                    PENDING = false;
                    if (rsdata.result < 0) {
                        $.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
                    } else {
                        $('#new_request_contact').html(rsdata.htmlreponse);
                        $('#dialog-notications').dialog('close').dialog('open'); 
                    }
                }
            }).call();
        },
        Save: function() {
            var Params = $('#_form_edit_panel').serializeObject();
            new backend({
                url: _CONFIG.COMMIT_URI,
                data: {
                    Params: Params,
                    Id: $('#conf_id').val()
                },
                callback: function(rsdata) {
                    if (rsdata.result < 0) {
                        $.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
                    } else {
                        $.jGrowl(rsdata.message);
                        _SOPLUGIN.Cancel();
                        _SOPLUGIN.Refresh();
                    }
                }
            }).call();
            return false;
        },
        OtherAdvand: function() {
            $('.otheradvand').toggle();
        },
        Cancel: function() {
            $('#dialog-notications').dialog('close');
        },
        DeleteItem: function(id) {
            ConfirmMsg(function() {
                backend({
                    url         :   _CONFIG.DELETE_URI,
                    data        :   {Id:id},
                    callback    :   function(rsdata){
                        if(rsdata.result<0){
                            $.jGrowl(rsdata.message,{ sticky: true, theme: 'growl-error', header: 'Error!' });
                        }else{
                            $.jGrowl(rsdata.message);
                            _SOPLUGIN.Refresh();
                        }
                    }
                }).call();
            }, 'These items will be permanently deleted and cannot be recovered. Are you sure ?')

        },
        RestoreItem: function() {
            accessdenied();
        },
        Permission: function(id) {

        },
        PrivateItem: function() {
            accessdenied();
        },
        Setting: function() {
            
        },
        Refresh: function() {
            this.LoadData(_CONFIG.PAGE);
        }
    };
}());
$(document).ready(function() {
    //Btree().Init();
});